
// filename os_tcp_ip.h

#ifndef   _OS_TCP_IP_H_
#define   _OS_TCP_IP_H_

#ifdef __Win32__
#include <windows.h>
#pragma comment(lib , "ws2_32.lib")

#elif __linux__

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <string>
#include <net/if.h>
#include <sys/ioctl.h>
#endif

#include "os_type.h"

#define MAX_ETH     32
#define MAX_IP      32
#define MAX_IP_STR  32
#define IP_END      (unsigned int) 0x32323333


extern char MACADDRESS[6];
extern bool g_isMacSet;

#if __Win32__
#define SOCKLEN    int
////////////////////////////////////////////////
// vs7.0,platform define


#include <IPHlpApi.h> 
//#pragma comment(lib, "Iphlpapi.lib")
/////////////////////////////////////////

#else
#define  SOCKLEN   socklen_t
#endif
namespace  OS
{
	typedef char*   pchar;
	typedef pchar*  ppchar;

	class IPLIST
	{
	public:
		IPLIST()
		{
			ipnum=0;
			pList = (long*) ::new long[MAX_IP]; 
			memset(pList,0,MAX_IP*sizeof(long));
		};
		~IPLIST(){if( pList ) ::delete[] pList; pList=0;};
		long get_ip(int i) const
		{
			if( pList && i < MAX_IP )
				return pList[i];
			return 0;
		};
		int get_ip_num(){return ipnum;};
	private:
		long *pList;
		int  ipnum;
		friend int get_mip(IPLIST* pl);
	};

#ifdef __Win32__
	bool InitWinsock();
	int  WinsockCleanup();
#endif

	int close_socket(int fd);

	// get all interface
	// in this function,it dont new char arrays
	int get_all_eth(char** ethlist);

	// get all ip in the host
	// now ,in linux ,can only get one ip of one eth
	int get_mip(IPLIST* pl);
}

#endif

